package com.alibaba.citrus.ots.b2b.trade.order.facade.common;

import com.epoch.app.bcots.platform_enhance.SaleOrderTag;
import com.epoch.app.otsb2btradecenter.enums.OrderStatus;
import com.epoch.app.otsb2btradecenter.sdo.OrderLineSDO;
import com.epoch.app.otsb2btradecenter.sdo.OrderSDO;


public class SetOrderTag {

    public static final String EXCHANGE="exchange";
    public static final String RETURN="return";
    public static final String NORMAL="normal";


    /** 根据订单的类型设置 订单标识 */
    public static void getOrderTag(String orderType , OrderSDO orderSDO){
        if (SaleOrderTag.EXCHANGE_ORDER.getCode().equals(orderType)) {
            orderSDO.setOrderTag(EXCHANGE);
        } else if (SaleOrderTag.LOGISTIC_RETURN_ORDER.getCode().equals(orderType) || SaleOrderTag.STD_RETURN_ORDER.getCode().equals(orderType)
                || SaleOrderTag.DS_STD_RETURN_ORDER.getCode().equals(orderType)|| SaleOrderTag.FREE_RETURN_ORDER.getCode().equals(orderType)) {
            orderSDO.setOrderTag(RETURN);
        }else {
            orderSDO.setOrderTag(NORMAL);
        }
    }

    public static String getOrderTag(String orderType){
        if (SaleOrderTag.EXCHANGE_ORDER.getCode().equals(orderType)) {
            return EXCHANGE;
        } else if (SaleOrderTag.LOGISTIC_RETURN_ORDER.getCode().equals(orderType) || SaleOrderTag.STD_RETURN_ORDER.getCode().equals(orderType) || SaleOrderTag.DS_STD_RETURN_ORDER.getCode().equals(orderType)) {
            return RETURN;
        }else {
            return NORMAL;
        }
    }

    /** 根据订单的标识 设置主单的状态  部分交货、部分处理、部分收货*/
    public static void setOrderSDOStatus(OrderSDO orderSDO){
        if (RETURN.equals(orderSDO.getOrderTag())) {
            orderSDO.setStatus(OrderStatus.PART_RECEIVING.getCode());
        } else if (EXCHANGE.equals(orderSDO.getOrderTag())) {
            orderSDO.setStatus(OrderStatus.PARTIAL_HANDLE.getCode());
        }else{
            orderSDO.setStatus(OrderStatus.PARTIAL_DELIVER.getCode());
        }
    }
    /** 根据订单的标识 设置子单的状态    部分交货、部分处理、部分收货*/
    public static void setOrderLineSDOStatus(OrderLineSDO orderLineSDO){
        if (RETURN.equals(orderLineSDO.getOrderLineTag())) {
            orderLineSDO.setStatus(OrderStatus.PART_RECEIVING.getCode());
        } else if (EXCHANGE.equals(orderLineSDO.getOrderLineTag())) {
            orderLineSDO.setStatus(OrderStatus.PARTIAL_HANDLE.getCode());
        }else{
            orderLineSDO.setStatus(OrderStatus.PARTIAL_DELIVER.getCode());
        }
    }

    /** 根据订单的标识 设置主单的状态  待交货、待处理、待收货*/
    public static void setOrderSDOStatusOne(OrderSDO orderSDO){
        if (RETURN.equals(orderSDO.getOrderTag())) {
            orderSDO.setStatus(OrderStatus.WAIT_RECEIVING.getCode());
        } else if (EXCHANGE.equals(orderSDO.getOrderTag())) {
            orderSDO.setStatus(OrderStatus.WAIT_HANDLE.getCode());
        }else{
            orderSDO.setStatus(OrderStatus.BEFORE_DELIVERY.getCode());
        }
    }
    /** 根据订单的标识 设置子单的状态    待交货、待处理、待收货*/
    public static void setOrderLineSDOStatusOne(OrderLineSDO orderLineSDO){
        if (RETURN.equals(orderLineSDO.getOrderLineTag())) {
            orderLineSDO.setStatus(OrderStatus.WAIT_RECEIVING.getCode());
        } else if (EXCHANGE.equals(orderLineSDO.getOrderLineTag())) {
            orderLineSDO.setStatus(OrderStatus.WAIT_HANDLE.getCode());
        }else{
            orderLineSDO.setStatus(OrderStatus.BEFORE_DELIVERY.getCode());
        }
    }



    /** sap006回调换货订单子单状态修改*/
    public static void setExchangeOrderLineSDOStatus(OrderLineSDO orderLineSDO){
        if (EXCHANGE.equals(orderLineSDO.getOrderLineTag())) {
            orderLineSDO.setStatus(OrderStatus.WAIT_HANDLE.getCode());
        }
        if (RETURN.equals(orderLineSDO.getOrderLineTag())) {
            orderLineSDO.setStatus(OrderStatus.WAIT_RECEIVING.getCode());
        }
    }
}
